/**
 * Pontifícia Universidade Católica do Paraná - PUCPR
 * Projeto Final de Ciência da Computação 
 * Ano: 2014
 * @author Florisvaldo
 */
package classes;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Vector;
import weka.core.Instances;


public class FileStruct {

    String path;
    String name;
    String relation;
    int NumberOfattribute;
    int NumberOfLines;
    int NumeberOfRegister;
    Vector atriVector;
    protected Instances m_Training = null;
    
    public FileStruct(String path, String Name) {
        this.path = path;
        this.name = Name;
        this.NumberOfattribute = 0;
        this.NumberOfLines = 0;
        this.NumeberOfRegister = 0;
        this.atriVector = new Vector();
        if (ReadStructOfFile()){
            
        }
    }
    private boolean ReadStructOfFile(){
        
        
        File file = new File(path);
        FileReader  reader;
        BufferedReader bufferRead;
        String line = "", lineConversion ="";
        
        try{
            reader = new FileReader(this.path);
            bufferRead = new BufferedReader(reader);
            
            while(bufferRead.ready()){
                line =  bufferRead.readLine();
                while("%".equals(line) || ("").equals(line) ){
                         line =  bufferRead.readLine();
                          this.NumberOfLines++;
                }
                if(line.length()>5){
                    lineConversion = line.substring(0, 10);
                    if(lineConversion.equalsIgnoreCase("@attribute")){
                        this.NumberOfattribute++;
                    }
                }
                lineConversion = line.substring(0, 5);
                if(lineConversion.equalsIgnoreCase("@data")){
                    while(bufferRead.ready()){
                        this.NumeberOfRegister++;
                        this.NumberOfLines++;
                        bufferRead.readLine();
                        return true;
                    }
                }
                this.NumberOfLines++;
            }
            bufferRead.close();
            reader.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        return false;
    }
    
    private boolean ReadFile() {
        
        boolean ret = false;
        File file = new File(path);
        FileReader  reader;
        BufferedReader bufferRead;
        String line = "", lineConversion = "";
        
        if (file.exists()){
            
            try{
                reader = new FileReader(this.path);
                bufferRead = new BufferedReader(reader);
                
                while(bufferRead.ready()){
                    
                    line = bufferRead.readLine();
                    while("%".equals(line) || ("").equals(line) ){
                         line =  bufferRead.readLine();
                          this.NumberOfLines++;
                    }
                    lineConversion = line.substring(0, 9);
                    if(lineConversion.equalsIgnoreCase("@RELATION")){
                       this.relation = lineConversion;
                    }
                    lineConversion = line.substring(0, 10);
                    if(lineConversion.equalsIgnoreCase("@attribute")){
                        /*
                         Minha ideia é colocar a linha toda como atributo e dividir no decorer.
                         * precios ainda mexer nos documentos 
                         */
                        if(this.atriVector.indexOf(lineConversion) > 0 ){
                            
                            
                                    
                        }else{
                            
                        }
                    }
                    
                    this.NumberOfLines++;
                }
            
            }catch(Exception e){
                e.printStackTrace();
                System.err.println("Descrição do erro: " + e.getMessage());
               // JOptionPane.showMessageDialog(null, "Erro ao verificar arquivo.\n"
               //         + "Para maiores informações entre em conta com o adm do systema\n");
                
            }
        
        }
        
        
        return ret;
    }
    
    
}
